package com.liushuo.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Timestamp;
import java.sql.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class DBUtil {
    private static final String url = "jdbc:mysql://localhost:3306/kscalsyslocal?useSSL=false&serverTimezone=Asia/Shanghai";
    private static final String user = "root";
    private static final String password = "1234";

    static {
        try {
			Class.forName("com.mysql.cj.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
    }

    public static Connection getConnection() {
    	try {
			return DriverManager.getConnection(url, user, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
    	return null;
    }

	public static Timestamp toStartOfDay(Date date) {
		if (date == null) {
			return null;
		}
		LocalDate localDate = date.toLocalDate();
		LocalDateTime startOfDay = localDate.atStartOfDay();
		return Timestamp.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
	}

	public static Timestamp toEndOfDay(Date date) {
		if (date == null) {
			return null;
		}
		LocalDate localDate = date.toLocalDate();
		LocalDateTime endOfDay = localDate.atTime(23, 59, 59, 999999999);
		return Timestamp.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
	}


}
